package com.coolweather.android.util;

import android.text.TextUtils;

import com.coolweather.android.db.Province;
import com.coolweather.android.gson.Weather;
import com.google.gson.Gson;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class Utility {

    public static Weather handleWeatherResponse(String response){
        try {
            JSONObject jsonObject = new JSONObject(response);//书中P331
            JSONArray jsonArray = jsonObject.getJSONArray("HeWeather");
            String weatherContent = jsonArray.getJSONObject(0).toString();//书中P332
            return new Gson().fromJson(weatherContent, Weather.class);//将JSON数据转化为Weather对象
        }catch (Exception e){
            e.printStackTrace();
        }
        return null;
    }
}
